package com.kuqi.service.impl;

import com.kuqi.domain.PageVo;
import com.kuqi.domain.User;
import com.kuqi.domain.Vo;
import com.kuqi.mapper.UserMapper;
import com.kuqi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author:kuqi
 * @createTime:2021/11/9 20:09
 * @description:
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void save(User user) {
        userMapper.save(user);
    }

    /**
     *
     * @return
     */
    @Override
    public Vo<User> getUserListByPage(PageVo pageVo) {
        /**
         * 分页的逻辑层要查询两个
         * 1.查询用户列表总记录数
         * 2.查询分页记录条数
         */
        int userTotal = userMapper.getUserTotal();
        List<User> userList = userMapper.getUserListByPage(pageVo);

        //将数据封装到
        Vo<User> userVo = new Vo<>();
        userVo.setTotal(userTotal);
        userVo.setDataList(userList);

        return userVo;
    }

    @Override
    public void updateUser(User user) {
        userMapper.update(user);
    }

    @Override
    public void deleteUserById(Integer id) {
        userMapper.deleteUserById(id);
    }

    @Override
    public User loginCheck(User user) {
        User result = userMapper.loginCheck(user);
        return result;
    }

    @Override
    public void register(User user) {
        userMapper.register(user);
    }

    @Override
    public User getUserById(Integer id) {
        User user = userMapper.getUserById(id);
        return user;
    }
}
